package com.imooc.common.thread;

import cn.hutool.core.thread.ThreadUtil;

import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by deng_wb on 2019/8/17
 */
public class ScheduledPoolTest {

    public static void main(String[] args)throws Exception {

        ScheduledExecutorService service = Executors.newScheduledThreadPool(4); // 定时器线程池
        service.scheduleAtFixedRate(()->{ // 以固定的频率执行任务
            ThreadUtil.sleep(new Random().nextInt(1000));
            System.out.println(Thread.currentThread().getName());

        },0,500, TimeUnit.MILLISECONDS);


    }
}
